package com.ec.file.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.ec.file.props.AliyunOssProperties;
import com.ec.file.props.FileUploadProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * 阿里云OSS bean
 * </p>
 *
 * @author Eric Lee
 * @since 2019-07-19 11:32
 */
@Slf4j
@Configuration
@ConditionalOnBean({AliyunOssProperties.class})
public class AliyunOssConfig {
    @Autowired
    private AliyunOssProperties aliOss;
    @Autowired
    private FileUploadProperties fileUploadProperties;

    @Bean
    public OSS ossClient() {
        return new OSSClientBuilder().build(aliOss.getEndPoint(), aliOss.getAccessKeyId(), aliOss.getAccessSecret());
    }
}
